﻿using Company.Core.Models;
using Company.Database.Base.Entities;
using Company.Database.Base.Repositories;
using Microsoft.AspNetCore.Mvc;

namespace Company.WebServer.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class StationController : ControllerBase
    {
        private readonly ILogger<WeatherForecastController> _logger;
        private IHospitalRepository HospitalRepository { get; }
        private IStationRepository StationRepository { get; }

        public StationController(
            ILogger<WeatherForecastController> logger,
            IStationRepository stationRepository,
            IHospitalRepository hospitalRepository)
        {
            StationRepository = stationRepository;
            HospitalRepository = hospitalRepository;
            _logger = logger;
        }
        [HttpGet]
        [Route("GetStations")]
        public async Task<IActionResult> GetStations([FromQuery] int hospitalId)
        {
            Result<List<StationEntity>> result = new();
            var entities = await StationRepository.GetAllAsync();
            if(entities==null || !entities.Any())
            {
                result.Message = "没有数据";
                return new JsonResult(result);
            }
            entities = entities.FindAll(t=>t.HospitalId == hospitalId);
            if(entities.Any())
            {
                result.Success = true;
                result.Message = "操作成功";
                result.Value = entities;
            }
            return new JsonResult(result);
        }
    }
}
